package com.iman.Confucius.service.impl.student;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.iman.Confucius.dto.RemarkStudyTimeDto;
import com.iman.Confucius.mappers.DrmCourseCategoryMapper;
import com.iman.Confucius.mappers.DrmCourseMapper;
import com.iman.Confucius.mappers.DrmStudyDmsgMapper;
import com.iman.Confucius.mappers.DrmStudyRemarkLogMapper;
import com.iman.Confucius.mappers.DrmStudyRemarkMapper;
import com.iman.Confucius.mappers.models.DrmCourse;
import com.iman.Confucius.mappers.models.DrmCourseCategory;
import com.iman.Confucius.mappers.models.DrmStudyDmsg;
import com.iman.Confucius.mappers.models.DrmStudyRemark;
import com.iman.Confucius.mappers.models.DrmStudyRemarkExample;
import com.iman.Confucius.mappers.models.DrmStudyRemarkLog;
import com.iman.Confucius.repository.IRedisGo;
import com.iman.Confucius.service.MongoMessageDetailService;
import com.iman.Confucius.service.student.CourseService;
import com.iman.Confucius.vo.CategReferencesVo;
import com.iman.Confucius.vo.CommentVo;
import com.iman.Confucius.vo.CourseClassmateVo;
import com.iman.Confucius.vo.CourseCtgVo;
import com.iman.Confucius.vo.CourseNoteVo;
import com.iman.Confucius.vo.CourseTeacherVo;
import com.iman.Confucius.vo.CourseVo;
import com.iman.Confucius.vo.ExamVo;
import com.iman.Confucius.vo.HomeworkVo;
import com.iman.Confucius.vo.ResourceVo;
import com.iman.Confucius.vo.StudyCourseVo;
import com.iman.Confucius.vo.student.StudyDmsgVo;
import com.iman.Confucius.vo.student.StudyRemarkVo;
import com.iman.common.hibernate.HibernateSupport;
import com.iman.common.hibernate.TemplateQLService;
import com.iman.common.support.Page;
import com.iman.common.util.IdCreater;

/**
 * @description 我的课程Service层实现
 * @author huangt
 * @date 2014年12月24日
 */
@Service("courseService")
@Transactional
public class CourseServiceImpl implements CourseService {
	@Inject
    TemplateQLService templateQLService;

    @Inject
    HibernateSupport  hibernateSupport;
    
    @Inject
    DrmCourseMapper  drmCourseMapper;
    
    @Autowired
    DrmCourseCategoryMapper  drmCourseCategoryMapper;
    
    @Autowired
    DrmStudyRemarkMapper	drmStudyRemarkMapper;
    
    @Autowired
    DrmStudyRemarkLogMapper	drmStudyRemarkLogMapper;
    @Autowired
    DrmStudyDmsgMapper  drmStudyDmsgMapper;
    @Inject
    IRedisGo  RedisGo;
    
    @Inject
	MongoMessageDetailService mongoService;
	
    private Logger logger = LoggerFactory.getLogger(CourseServiceImpl.class);


    
    /**
 	 * @description 获得user所有学习动态消息表
 	 * @param map
 	 * @return Page<StudyRemarkVo>
 	 * @throws Exception 
 	 * @author syd  2014年12月29日
 	 */
    @Override
	public Page<StudyRemarkVo> getStudyRemarkList(Map<String, Object> map) throws Exception {
		Integer currentPage = (Integer)map.get("pageIndex");
		Integer pageSize  = (Integer)map.get("pageSize");
		long userId = (Long) map.get("userId");
		Map<String, Object> hashMapParams = new HashMap<String, Object>();
		hashMapParams.put("userId", userId);
		Page<StudyRemarkVo>  list  =  templateQLService.findByPagedSQLBeanQuery("query-study-remark-list", hashMapParams, Page.getStartOfPage(currentPage,pageSize), pageSize,StudyRemarkVo.class);
		return  list;
	}
    /**
	 * @description 获得user所有学习动态消息表
	 * @param map
	 * @return Page<StudyDmsgVo>
	 * @throws Exception 
	 * @author syd  2014年12月28日
	 */
    @Override
	public Page<StudyDmsgVo> getAllStudyDmsgList(Map<String, Object> map) throws Exception {
		Integer currentPage = (Integer)map.get("pageIndex");
		Integer pageSize  = (Integer)map.get("pageSize");
		long userId = (Long) map.get("userId");
		Map<String, Object> hashMapParams = new HashMap<String, Object>();
		hashMapParams.put("userId", userId);
		Page<StudyDmsgVo>  list  =  templateQLService.findByPagedSQLBeanQuery("query-dmsg-list", hashMapParams, Page.getStartOfPage(currentPage,pageSize), pageSize,StudyDmsgVo.class);
		return  list;
	}
	/**
	 * @description 获得所有课程列表
	 * @param map
	 * @return Page<CourseVo>
	 * @throws Exception 
	 * @author huangt  2014年12月24日
	 */
	public Page<CourseVo> getAllCourseList(Map<String, Object> map) throws Exception {
		Integer currentPage = (Integer)map.get("pageIndex");
		Integer pageSize  = (Integer)map.get("pageSize");
		long userId = (Long) map.get("userId");
		Map<String, Object> hashMapParams = new HashMap<String, Object>();
		hashMapParams.put("userId", userId);
		hashMapParams.put("courseId", map.get("courseId"));
		hashMapParams.put("courseSubject", map.get("courseSubject"));
		hashMapParams.put("courseOnlinetp", map.get("courseOnlinetp"));
		Page<CourseVo>  list  =  templateQLService.findByPagedSQLBeanQuery("query-course-list", hashMapParams, Page.getStartOfPage(currentPage,pageSize), pageSize,CourseVo.class);
		List<CourseVo> cvList = list.getData();
		for (CourseVo cv : cvList) {
			if(mongoService.findById(cv.getCourseDesc()) != null){
				if(mongoService.findById(cv.getCourseDesc()) != null){
					cv.setCourseDesc(mongoService.findById(cv.getCourseDesc()).getDetailContent());
				}
			}
		}
		list.setData(cvList);
		return  list;
	}
	
	
	
	
	/**
	 * 
	 *  Function:
	 *  功能说明：公开课获取列表
	 *	 使用说明：
	 *  @author  wangxiaolei  DateTime 2015年11月18日 下午11:07:12
	 *	返回类型: Page<CourseVo>    
	 *  @param map
	 *  @return
	 *  @throws Exception
	 */
	public Page<CourseVo> getAllPublicCourseList(Map<String, Object> map) throws Exception {
		Integer currentPage = (Integer)map.get("pageIndex");
		Integer pageSize  = (Integer)map.get("pageSize");
		Map<String, Object> hashMapParams = new HashMap<String, Object>();
		hashMapParams.put("courseId", map.get("courseId"));
		hashMapParams.put("courseSubject", map.get("courseSubject"));
		hashMapParams.put("courseOnlinetp", map.get("courseOnlinetp"));
		Page<CourseVo>  list  =  templateQLService.findByPagedSQLBeanQuery("query-course-public-list", hashMapParams, Page.getStartOfPage(currentPage,pageSize), pageSize,CourseVo.class);
		List<CourseVo> cvList = list.getData();
		for (CourseVo cv : cvList) {
			if(mongoService.findById(cv.getCourseDesc()) != null){
				if(mongoService.findById(cv.getCourseDesc()) != null){
					cv.setCourseDesc(mongoService.findById(cv.getCourseDesc()).getDetailContent());
				}
			}
		}
		list.setData(cvList);
		return  list;
	}
	
	/**
	 * @description 根据ID获得教师信息
	 * @param id
	 * 			教师ID
	 * @return CourseTeacherVo
	 * @throws Exception 
	 * @author huangt  2015年1月4日
	 */
	public CourseTeacherVo getCourseTeacherById(long id) throws Exception {
		Integer currentPage = 0;
		Integer pageSize  = 5;
		CourseTeacherVo teacher = new CourseTeacherVo();
		Map<String, Object> hashMapParams = new HashMap<String, Object>();
		hashMapParams.put("userId", id);
		Page<CourseTeacherVo>  list  =  templateQLService.findByPagedSQLBeanQuery("query-course-teacher", hashMapParams, Page.getStartOfPage(currentPage,pageSize), pageSize,CourseTeacherVo.class);
		if (list.getTotalCount() > 0) {
			teacher = list.getData().get(0);
		}
		return  teacher;
	}
	
	/**
	 * @description 根据类型获得课程列表
	 * @param map
	 * @return Page<CourseVo>
	 * @throws Exception 
	 * @author huangt  2014年12月25日
	 */
	public Page<CourseVo> getCourseListByType(Map<String, Object> map) throws Exception {
		Integer currentPage = (Integer)map.get("pageIndex");
		Integer pageSize  = (Integer)map.get("pageSize");
		long userId = (Long) map.get("userId");
		Map<String, Object> hashMapParams = new HashMap<String, Object>();
		hashMapParams.put("userId", userId);
		hashMapParams.put("courseType", map.get("courseType"));
		Page<CourseVo>  list  =  templateQLService.findByPagedSQLBeanQuery("query-type-course-list", hashMapParams, Page.getStartOfPage(currentPage,pageSize), pageSize,CourseVo.class);
		List<CourseVo> cvList = list.getData();
		for (CourseVo cv : cvList) {
			if(mongoService.findById(cv.getCourseDesc()) != null){
				if(mongoService.findById(cv.getCourseDesc()) != null){
					cv.setCourseDesc(mongoService.findById(cv.getCourseDesc()).getDetailContent());
				}
			}
		}
		list.setData(cvList);
		return  list;
	}
	
	/**
	 * @description 获得专题课程的课程列表
	 * @param map
	 * @return Page<CourseVo>
	 * @throws Exception 
	 * @author huangt  2014年12月26日
	 */
	public Page<CourseVo> getTopicCourseList(Map<String, Object> map) throws Exception {
		Integer currentPage = (Integer)map.get("pageIndex");
		Integer pageSize  = (Integer)map.get("pageSize");
		long userId = (Long) map.get("userId");
		Map<String, Object> hashMapParams = new HashMap<String, Object>();
		hashMapParams.put("userId", userId);
		hashMapParams.put("courseId", map.get("courseId"));
		hashMapParams.put("subjectId", map.get("subjectId"));
//		hashMapParams.put("courseSubject", map.get("courseSubject"));
		Page<CourseVo>  list  =  templateQLService.findByPagedSQLBeanQuery("query-topic-course-list", hashMapParams, Page.getStartOfPage(currentPage,pageSize), pageSize,CourseVo.class);
		List<CourseVo> cvList = list.getData();
		for (CourseVo cv : cvList) {
			if(mongoService.findById(cv.getCourseDesc()) != null){
				cv.setCourseDesc(mongoService.findById(cv.getCourseDesc()).getDetailContent());
			}
		}
		list.setData(cvList);
		return  list;
	}
	
	/**
	 * @description 获得课程课件列表
	 * @return Page<CourseCtgVo>
	 * @throws Exception 
	 * @author huangt  2014年12月26日
	 */
	public Page<CourseCtgVo> getCourseCtgList(Map<String, Object> map) throws Exception {
		Integer currentPage = (Integer)map.get("pageIndex");
		Integer pageSize  = (Integer)map.get("pageSize");
		Map<String, Object> hashMapParams = new HashMap<String, Object>();
		hashMapParams.put("courseId", map.get("courseId"));
		Page<CourseCtgVo>  list  =  templateQLService.findByPagedSQLBeanQuery("query-course-category", hashMapParams, 
				Page.getStartOfPage(currentPage, pageSize), pageSize, CourseCtgVo.class);
		if (list.getData() != null) {
			//设置课时对应的作业和考试  huangt  2014-12-30
			for (CourseCtgVo courseCtgVo : list.getData()) {
				long ctgId = courseCtgVo.getId();
				hashMapParams.put("categoryId", ctgId);
				Page<HomeworkVo> homework = templateQLService.findByPagedSQLBeanQuery("query-course-ctg-homework", 
						hashMapParams, Page.getStartOfPage(currentPage, pageSize), pageSize, HomeworkVo.class);;
				if (homework.getData() != null  && homework.getData().size()>0) {
					courseCtgVo.setHomeworkVo(homework.getData() );
				}
				Page<ExamVo> exam = templateQLService.findByPagedSQLBeanQuery("query-course-ctg-exam", 
						hashMapParams, Page.getStartOfPage(currentPage, pageSize), pageSize, ExamVo.class);
				if (exam.getData() != null && exam.getData().size()>0 ) {
					courseCtgVo.setExamVo(exam.getData() );
				}
			}
		}
		return  list;
	}
	
	/**
	 * @description 获得课时作业列表
	 * @param map
	 * @return Page<HomeworkVo>
	 * @throws Exception 
	 * @author huangt  2014年12月30日
	 */
	public Page<HomeworkVo> getCtgHomework(Map<String, Object> map) throws Exception {
		Integer currentPage = (Integer)map.get("pageIndex");
		Integer pageSize  = (Integer)map.get("pageSize");
		Map<String, Object> hashMapParams = new HashMap<String, Object>();
		hashMapParams.put("categoryId", map.get("categoryId"));
		hashMapParams.put("homeworkId", map.get("homeworkId"));
		Page<HomeworkVo>  list  =  templateQLService.findByPagedSQLBeanQuery("query-course-ctg-homework", hashMapParams, Page.getStartOfPage(currentPage, pageSize), pageSize, HomeworkVo.class);
		return  list;
	}
	
	/**
	 * @description 获得课时考试列表
	 * @param map
	 * @return Page<ExamVo>
	 * @throws Exception 
	 * @author huangt  2014年12月30日
	 */
	public Page<ExamVo> getCtgExam(Map<String, Object> map) throws Exception {
		Integer currentPage = (Integer)map.get("pageIndex");
		Integer pageSize  = (Integer)map.get("pageSize");
		Map<String, Object> hashMapParams = new HashMap<String, Object>();
		hashMapParams.put("categoryId", map.get("categoryId"));
		Page<ExamVo>  list  =  templateQLService.findByPagedSQLBeanQuery("query-course-ctg-exam", hashMapParams, Page.getStartOfPage(currentPage, pageSize), pageSize, ExamVo.class);
		return  list;
	}
	
	/**
	 * @description 获得课时资源列表
	 * @param map
	 * @return Page<ResourceVo>
	 * @throws Exception 
	 * @author huangt  2014年12月31日
	 */
	public Page<ResourceVo> getCtgResource(Map<String, Object> map) throws Exception {
		Integer currentPage = (Integer)map.get("pageIndex");
		Integer pageSize  = (Integer)map.get("pageSize");
		Map<String, Object> hashMapParams = new HashMap<String, Object>();
		hashMapParams.put("srcId", map.get("srcId"));
		Page<ResourceVo>  list  =  templateQLService.findByPagedSQLBeanQuery("query-course-ctg-resource", hashMapParams, Page.getStartOfPage(currentPage, pageSize), pageSize, ResourceVo.class);
		return  list;
	}
	
	/**
	 * @description 获得课程笔记列表
	 * @param map
	 * @return Page<CourseNoteVo>
	 * @throws Exception 
	 * @author huangt  2014年12月26日
	 */
	public Page<CourseNoteVo> getCourseNoteList(Map<String, Object> map) throws Exception {
		Integer currentPage = (Integer)map.get("pageIndex");
		Integer pageSize  = (Integer)map.get("pageSize");
		Map<String, Object> hashMapParams = new HashMap<String, Object>();
		hashMapParams.put("courseId", map.get("courseId"));
		Page<CourseNoteVo>  list  =  templateQLService.findByPagedSQLBeanQuery("query-course-note", hashMapParams, Page.getStartOfPage(currentPage, pageSize), pageSize, CourseNoteVo.class);
		return  list;
	}
	
	/**
	 * @description 获得课程同学列表
	 * @param map
	 * @return Page<CourseClassmateVo>
	 * @throws Exception 
	 * @author huangt  2014年12月29日
	 */
	public Page<CourseClassmateVo> getCourseClassmateList(Map<String, Object> map) throws Exception {
		Integer currentPage = (Integer)map.get("pageIndex");
		Integer pageSize  = (Integer)map.get("pageSize");
		Map<String, Object> hashMapParams = new HashMap<String, Object>();
		hashMapParams.put("courseId", map.get("courseId"));
		Page<CourseClassmateVo>  list  =  templateQLService.findByPagedSQLBeanQuery("query-course-classmate", hashMapParams, Page.getStartOfPage(currentPage, pageSize), pageSize, CourseClassmateVo.class);
		return  list;
	}
	
	/**
	 * @description 获得课程评论列表
	 * @param map
	 * @return Page<CommentVo>
	 * @throws Exception 
	 * @author huangt  2014年12月29日
	 */
	public Page<CommentVo> getCourseCommentList(Map<String, Object> map) throws Exception {
		Integer currentPage = (Integer)map.get("pageIndex");
		Integer pageSize  = (Integer)map.get("pageSize");
		Map<String, Object> hashMapParams = new HashMap<String, Object>();
		hashMapParams.put("courseId", map.get("courseId"));
		hashMapParams.put("commontPid", map.get("commontPid"));
		Page<CommentVo>  list  =  templateQLService.findByPagedSQLBeanQuery("query-course-comment", hashMapParams, Page.getStartOfPage(currentPage, pageSize), pageSize, CommentVo.class);
		return  list;
	}
	
	/**
	 * @description 根据课件获得资源列表
	 * @param map
	 * @return Page<ResourceVo>
	 * @throws Exception 
	 * @author huangt  2015年1月4日
	 */
	public Page<ResourceVo> getCourseResList(Map<String, Object> map) throws Exception {
		Integer currentPage = (Integer)map.get("pageIndex");
		Integer pageSize  = (Integer)map.get("pageSize");
		Map<String, Object> hashMapParams = new HashMap<String, Object>();
		hashMapParams.put("courseId", map.get("courseId"));
		Page<ResourceVo>  list  =  templateQLService.findByPagedSQLBeanQuery("query-course-resource-list", hashMapParams, Page.getStartOfPage(currentPage, pageSize), pageSize, ResourceVo.class);
		return  list;
	}
	
	/**
	 * 获取  此课程中所有的  课件中包含的   上传资料
	 */
	public Page<CategReferencesVo> getCourseeferencesList(Map<String, Object> map) throws Exception {
		Integer currentPage = (Integer)map.get("pageIndex");
		Integer pageSize  = (Integer)map.get("pageSize");
		Map<String, Object> hashMapParams = new HashMap<String, Object>();
		hashMapParams.put("courseId", map.get("courseId"));
		Page<CategReferencesVo>  list  =  templateQLService.findByPagedSQLBeanQuery("query-course-references-list", hashMapParams, Page.getStartOfPage(currentPage, pageSize), pageSize, CategReferencesVo.class);
		return  list;
	}
	
	
	
	@Override
	public Page<StudyCourseVo> getStudyingCourseList(Long userId) {
		Map<String, Object> hashMapParams = new HashMap<String, Object>();
		if(userId == null){
			throw new IllegalArgumentException("无效用户标识");
		}
		hashMapParams.put("userId", userId);
		Page<StudyCourseVo>  pageObject  =  templateQLService.findByPagedSQLBeanQuery("query-studying-courses", hashMapParams, Page.getStartOfPage(0, 10000), 10000, StudyCourseVo.class);
		return  pageObject;
	}
	
	
	/**
	 * 
	 */
	@Override
	public DrmCourse getCouserById(long courseId) {
		return  this.drmCourseMapper.selectByPrimaryKey(courseId);
	}
	
	
	
	/**
	 *  Function:
	 *  功能说明： 判断如果是过程话学习的话，根据进度， 判断  是否可以学习下一个 课件
	 *	 使用说明：
	 *  @author  wangxiaolei  DateTime 2015年1月25日 下午11:09:08
	 *	返回类型: Integer    
	 *  @param map
	 *  @return
	 */
	public Integer  	canStudyNextCategory(Map<String,Object> map){
		BigInteger  cnt = (BigInteger)this.templateQLService .findSQL( "query-studying-canstudynext", map);
		return cnt.intValue();
	}
	
	/**
	 * 设置二十秒失效次key
	 */
	@Override
	public String  studyKey(String key ,String  value) {
		this.RedisGo.putKV(key, value,20);
		return key;
	}
	
	/**
	 * 
	 */
	@Override
	public boolean exsitStudyKey(String key) {
		String value = this.RedisGo.getKV(key);
		return ( value==null || "".equals(value) ) ?false:true;
	}
	
	
	/**
	 * 
	 */
	@Override
	public DrmCourseCategory getCourseCategoryById(String id) {
		DrmCourseCategory cate = this.drmCourseCategoryMapper.selectByPrimaryKey( NumberUtils.toLong(id));
		return cate;
	}
	
	
	
	/**
	 * 根据特定的key，设置  内容
	 */
	@Override
	public boolean setRemarkStudentStudyTime(Map<String, String> value) {
		logger.info("set study remark=:"+value);
		boolean result = this.RedisGo.putMap(CourseService.REMARK_STUDENT_STUDY_MAP_MAINKEY,value);
		logger.info("set study remark  result=:"+result);
		return result;
	}
	
	
	/**
	 * 
	 */
	@Override
	public Map<String, String> getRemarkStudentStudyTime() {
		logger.info("set study remark=:"+CourseService.REMARK_STUDENT_STUDY_MAP_MAINKEY);
		Map<String, String>  result = this.RedisGo.getMap( CourseService.REMARK_STUDENT_STUDY_MAP_MAINKEY);
		logger.info("set study remark  result=:"+result);
		return result;
	}
	
	
	/**
	 * 
	 */
	@Override
	public DrmStudyRemark getStudentStudymark(RemarkStudyTimeDto dto) {
		DrmStudyRemarkExample example = new DrmStudyRemarkExample();
		example.createCriteria().andCourseIdEqualTo( Long.parseLong( dto.getCourseId())).andCategoryIdEqualTo(Long.parseLong(dto.getCtgId()))
		.andUserIdEqualTo( dto.getUserId());
		List<DrmStudyRemark> remarks = this.drmStudyRemarkMapper.selectByExample(example);
		
		if(remarks!=null && remarks.size()>0){
			return remarks.get(0);
		}
		return null;
	}
	
	
	/**
	 * 
	 */
	public boolean updateDrmStudyRemark(DrmStudyRemark remarkold  ,DrmStudyRemark remarknew  ,String courseName,String categrotyName,String username ) {
		//更新
		this.drmStudyRemarkMapper.updateByPrimaryKey(remarknew);
		//增加  变化的log
		DrmStudyRemarkLog log = new DrmStudyRemarkLog();
		try{
			if(remarkold == null)
			{
				BeanUtils.copyProperties(log, remarknew);
			}else{
				BeanUtils.copyProperties(log, remarknew);
			}
			log.setId( IdCreater.getId());
			this.drmStudyRemarkLogMapper.insertSelective(log);
		}catch(Exception e){
			e.printStackTrace();
		}
		
		//插入 学习动态信息
		insterDmsg(  remarknew,  courseName,  categrotyName,  username,remarkold==null);
		
		
		return true;
	};


	/**
	 * 
	 *  Function:
	 *  功能说明：
	 *	 使用说明：
	 *  @author  wangxiaolei  DateTime 2015年5月10日 下午6:10:29
	 *	返回类型: void    
	 *  @param remarknew
	 *  @param courseName
	 *  @param categrotyName
	 *  @param username
	 */
	public void insterDmsg(DrmStudyRemark remarknew,String courseName,String categrotyName,String username ,boolean first){

		//增加   学习动态消息的内容
		DrmStudyDmsg dmsg = new DrmStudyDmsg();
		dmsg.setCategoryId(remarknew.getCategoryId());
		dmsg.setCategoryNm(categrotyName );
		dmsg.setCourseId(remarknew.getCourseId() );
		dmsg.setCourseNm(courseName);
		dmsg.setId(IdCreater.getId());
		dmsg.setOperaterDt(new DateTime());
		if(first){
				dmsg.setOperaterTp(DrmStudyDmsg.OPERATER_TP.开始学习.ordinal());
		}else{
			if(remarknew.getProgress()>95){
				dmsg.setOperaterTp(DrmStudyDmsg.OPERATER_TP.学习完成.ordinal());
			}else{
				dmsg.setOperaterTp(DrmStudyDmsg.OPERATER_TP.正在学习.ordinal());
			}
		}
		
		dmsg.setUserId( remarknew.getUserId());
		dmsg.setUserName( username);
		drmStudyDmsgMapper.insert(dmsg);
		
	}
	@Override
	public List<Map<String, String>> getCourseTop5() {
		// TODO Auto-generated method stub
		 List<Map<String, String>> map =  templateQLService.findBySQLMapQuery("query_course_top_5", null);
		return map;
	}
	@Override
	public boolean addCourseComment(CommentVo cv) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("id", cv.getId());
		params.put("userId", cv.getUserId());
		params.put("courseId", cv.getCourseId());
		params.put("commontText", cv.getCommontText());
		params.put("commontPid", cv.getCommontPid());
		params.put("commentStar", cv.getCommentStar());
		params.put("commontSeq", cv.getCommontSeq());
		int res = templateQLService.executeSQLUpdate("add_course_comment", params);
		int res1 = templateQLService.executeSQLUpdate("add_course_count", params);
		if(res > 0 && res1 > 0) return true;
		return false;
	};
}

